package com.emergency.db.controller.item;

import com.emergency.common.entity.Result;
import com.emergency.common.entity.StatusCode;
import com.emergency.db.domain.item.ItemDetail;
import com.emergency.db.service.item.ItemDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/item/detail")
@CrossOrigin
public class ItemDetailController {
    @Autowired
    ItemDetailService itemDetailService;

    //查询ByItem单项
    @RequestMapping(value = "/search/item/{id}", method = RequestMethod.POST)
    public Result findById(@PathVariable("id") Long id) {
        ItemDetail itemDetail = itemDetailService.findByItem(id);
        return new Result(true, StatusCode.OK, "查询成功", itemDetail);
    }

    //分页
    @RequestMapping(value = "/list/{page}/{size}", method = RequestMethod.POST)
    public Result list(@RequestBody Map searchMap, @PathVariable int page, @PathVariable int size) {
        Page<ItemDetail> pageList = itemDetailService.findList(searchMap, page, size);
        return new Result(true, StatusCode.OK, "操作成功", pageList);
    }

}
